//
//  CustomTabBarController.m
//  ZhiLianZhaoPin
//
//  Created by 可 孙 on 12-12-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CustomTabBarController.h"

@implementation CustomTabBarController
@synthesize barView;
@synthesize imaView0;
@synthesize imaView1;
@synthesize imaView2;
@synthesize imaView3;
@synthesize imaView4;

- (void)dealloc {
    self.barView=nil;
    self.imaView0=nil;
    self.imaView1=nil;
    self.imaView2=nil;
    self.imaView3=nil;
    self.imaView4=nil;
    [super dealloc];
}
- (id)init {
    self = [super init];
    if (self) {
        self.barView=[[[UIView alloc]initWithFrame:CGRectMake(0, 436, 320, 44)]autorelease];
        //设置背景图片
        UIImageView * bgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
        [bgView setImage:[UIImage imageNamed:TABBARIMAGE]];
        [self.barView addSubview:bgView];
        [bgView release];
        //添加item
        self.imaView0=[[UIImageView alloc]initWithFrame:CGRectMake(0, 3, 64, 38)];
        self.imaView0.backgroundColor=[UIColor clearColor];
        self.imaView0.userInteractionEnabled=YES;
        UITapGestureRecognizer * tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1Begine:)];
        [self.imaView0 addGestureRecognizer:tap1];
        [tap1 release];
        [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1TOUCHED]];
        [self.barView addSubview:self.imaView0];
        [self.imaView0 release];
        
        self.imaView1=[[UIImageView alloc]initWithFrame:CGRectMake(64, 3, 64, 38)];
        self.imaView1.backgroundColor=[UIColor clearColor];
        self.imaView1.userInteractionEnabled=YES;
        UITapGestureRecognizer * tap2=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap2Begine:)];
        [self.imaView1 addGestureRecognizer:tap2];
        [tap2 release];
        [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2UNTOUCHED]];
        [self.barView addSubview:self.imaView1];
        [self.imaView1 release];
        
        self.imaView2=[[UIImageView alloc]initWithFrame:CGRectMake(128, 3, 64, 38)];
        self.imaView2.backgroundColor=[UIColor clearColor];
        self.imaView2.userInteractionEnabled=YES;
        UITapGestureRecognizer * tap3=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap3Begine:)];
        [self.imaView2 addGestureRecognizer:tap3];
        [tap3 release];
        [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3UNTOUCHED]];
        [self.barView addSubview:self.imaView2];
        [self.imaView2 release];
        
        self.imaView3=[[UIImageView alloc]initWithFrame:CGRectMake(192, 3, 64, 38)];
        self.imaView3.backgroundColor=[UIColor clearColor];
        self.imaView3.userInteractionEnabled=YES;
        UITapGestureRecognizer * tap4=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap4Begine:)];
        [self.imaView3 addGestureRecognizer:tap4];
        [tap4 release];
        [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4UNTOUCHED]];
        [self.barView addSubview:self.imaView3];
        [self.imaView3 release];
        
        self.imaView4=[[UIImageView alloc]initWithFrame:CGRectMake(256, 3, 64, 38)];
        self.imaView4.backgroundColor=[UIColor clearColor];
        self.imaView4.userInteractionEnabled=YES;
        UITapGestureRecognizer * tap5=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap5Begine:)];
        [self.imaView4 addGestureRecognizer:tap5];
        [tap5 release];
        [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5UNTOUCHED]];
        [self.barView addSubview:self.imaView4];
        [self.imaView4 release];
        
        [self.view addSubview:self.barView];
    }
    return self;
}
-(void)tap1Begine:(UITapGestureRecognizer *)gesture
{
    self.selectedIndex=0;
    [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1TOUCHED]];
    [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2UNTOUCHED]];
    [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3UNTOUCHED]];
    [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4UNTOUCHED]];
    [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5UNTOUCHED]];
}
-(void)tap2Begine:(UITapGestureRecognizer *)gesture
{
    self.selectedIndex=1;
    [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1UNTOUCHED]];
    [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2TOUCHED]];
    [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3UNTOUCHED]];
    [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4UNTOUCHED]];
    [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5UNTOUCHED]];
}
-(void)tap3Begine:(UITapGestureRecognizer *)gesture
{
    self.selectedIndex=2;
    [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1UNTOUCHED]];
    [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2UNTOUCHED]];
    [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3TOUCHED]];
    [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4UNTOUCHED]];
    [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5UNTOUCHED]];
}
-(void)tap4Begine:(UITapGestureRecognizer *)gesture
{
    self.selectedIndex=3;
    [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1UNTOUCHED]];
    [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2UNTOUCHED]];
    [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3UNTOUCHED]];
    [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4TOUCHED]];
    [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5UNTOUCHED]];
}
-(void)tap5Begine:(UITapGestureRecognizer *)gesture
{
    self.selectedIndex=4;
    [self.imaView0 setImage:[UIImage imageNamed:TABBAARITEM1UNTOUCHED]];
    [self.imaView1 setImage:[UIImage imageNamed:TABBAARITEM2UNTOUCHED]];
    [self.imaView2 setImage:[UIImage imageNamed:TABBAARITEM3UNTOUCHED]];
    [self.imaView3 setImage:[UIImage imageNamed:TABBAARITEM4UNTOUCHED]];
    [self.imaView4 setImage:[UIImage imageNamed:TABBAARITEM5TOUCHED]];
}
@end
